package com.sg.service.biz.framework.impl;

import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.framework.req.CheckCaptchaValidReqDto;
import com.sg.dto.biz.framework.res.CheckCaptchaValidRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class CaptchaServiceImpl implements com.wicket.okrframework.biz.service.CaptchaService {
    @Resource
    private RedisUtil redisUtil;
    //@Resource
    //private MSpecMethordTableService mSpecMethordTableService;
    @Resource
    private NbCaptcha nbCaptcha;

    /**
     * D1-检测验证码是否有效（特殊方法）[1185]
     * gen by moon at 10/2/2022, 12:00:37 AM
     */
    @Trace(operationName = "D1-检测验证码是否有效（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public CheckCaptchaValidRespDto checkCaptchaValid(CheckCaptchaValidReqDto reqDto) {


        CheckCaptchaValidRespDto checkCaptchaValidRes_1 = null;
//步骤0: M-检测验证码是否有效（特殊方法） - checkCaptchaValid
        //ModelCode: checkCaptchaValid
        CheckCaptchaValidRespDto checkCaptchaValidRes = null;
        CheckCaptchaValidReqDto checkCaptchaValidReq = new CheckCaptchaValidReqDto();
        if (reqDto != null) {
            checkCaptchaValidReq.setPhone(reqDto.getPhone());//SimpleFieldAssign//sourceId:43316_1
            checkCaptchaValidReq.setVerificationCode(reqDto.getVerificationCode());//SimpleFieldAssign//sourceId:43293_1
        }

        /*M-检测验证码是否有效（特殊方法）[1421]  用于检测用户前端录入验证码是否有效 */

        checkCaptchaValidRes = nbCaptcha.checkCaptchaValid(checkCaptchaValidReq);


        checkCaptchaValidRes_1 = checkCaptchaValidRes;

        CheckCaptchaValidRespDto retData = new CheckCaptchaValidRespDto();
        if (checkCaptchaValidRes_1 != null) {
            retData.setIsInvalid(checkCaptchaValidRes_1.getIsInvalid());//SimpleFieldAssign//sourceId:43363_1
        }


        return retData;
    }

    //
}
